package com.partsoft.utils;

public abstract class RandomUtils {

	public static final char[] LOWER_CHARS = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
			'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };

	public static final char[] UPPER_CHARS= { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'G', 'I', 'J', 'K', 'L', 'M', 'N',
			'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };

	public static int randomInteger() {
		int magicNumber = 0;
		for (int i = 0; i < 8; i++) {
			int random = (int) (Math.random() * 32.0D) & 0xF;
			magicNumber = magicNumber << 4 | random;
		}
		return magicNumber;
	}

	public static String randomDecimals(int length) {
		char[] chars = new char[length];
		for (int i = 0; i < length; i++) {
			int random = (int) (Math.random() * 10.0D) % 10;
			chars[i] = NumericUtils.NUMBER_CHARS[random];
		}
		return new String(chars);
	}

	public static String randomString(int length) {
		char[] chars = new char[length];
		for (int i = 0; i < length; i++) {
			int random = (int) (Math.random() * 3.0D) & 0x3;
			switch (random) {
			case 0:
				random = (int) (Math.random() * 10.0D) % 10;
				chars[i] = NumericUtils.NUMBER_CHARS[random];
				break;
			case 1:
				random = (int) (Math.random() * 26.0D) % 26;
				chars[i] = LOWER_CHARS[random];
				break;
			case 2:
				random = (int) (Math.random() * 26.0D) % 26;
				chars[i] = UPPER_CHARS[random];
			}
		}
		return new String(chars);
	}
}